#!/bin/bash

# 检查PDF文件保存位置的脚本

echo "=== 检查PDF保存路径配置 ==="
echo ""

# 检查系统属性
echo "1. 检查系统属性 sonar.path.data:"
if [ -n "$sonar_path_data" ]; then
    echo "   设置值: $sonar_path_data"
else
    echo "   未设置，将使用默认值"
fi

echo ""
echo "2. 检查默认路径:"
echo "   /opt/sonarqube/data/"
if [ -d "/opt/sonarqube/data" ]; then
    echo "   ✓ 目录存在"
    echo "   目录权限: $(ls -ld /opt/sonarqube/data)"
else
    echo "   ✗ 目录不存在"
fi

echo ""
echo "3. 检查SonarQube工作目录:"
echo "   通常路径: /opt/sonarqube/temp 或 /tmp"

echo ""
echo "4. 查找已生成的PDF文件:"
echo "   在常见位置查找PDF文件..."
find /opt/sonarqube -name "*.pdf" -type f 2>/dev/null | head -10
find /tmp -name "*.pdf" -type f 2>/dev/null | head -10

echo ""
echo "5. Docker环境检查:"
if [ -f /.dockerenv ]; then
    echo "   ✓ 运行在Docker容器中"
    echo "   挂载卷: $(mount | grep sonar)"
else
    echo "   ✗ 非Docker环境"
fi

echo ""
echo "=== 使用建议 ==="
echo ""
echo "设置自定义路径的方法:"
echo "1. Docker运行时:"
echo "   docker run -e SONARQUBE_OPTS=\"-Dsonar.path.data=/custom/path\" ..."
echo ""
echo "2. 直接设置:"
echo "   在sonar.properties中添加: sonar.path.data=/custom/path"
echo ""
echo "3. Java参数:"
echo "   java -Dsonar.path.data=/custom/path ..."